package com.lzx.iteam.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.lzx.iteam.R;

/**
 * Created by Megan on 16/5/24.
 */
public class WeeklyChooseYearMonthAdapter extends BaseAdapter {

    private String[] strings;
    private Context mContext;
    private int type;//0:年份选择  1：月份选择
    private int yearPostion=-1;
    private int monthPosition=-1;

    public WeeklyChooseYearMonthAdapter(Context context, int type) {
        this.mContext = context;
        this.type = type;
    }

    public void setChooseYear(int position) {
        yearPostion = position;
        notifyDataSetChanged();
    }

    public void setChooseMonth(int position) {
        monthPosition = position;
        notifyDataSetChanged();
    }

    public void bindData(String[] strings) {
        this.strings = strings;
    }

    @Override
    public int getCount() {
        return strings.length;
    }

    @Override
    public Object getItem(int position) {
        return strings[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.weekly_main_month_select_item, null);
            holder.text = (TextView) convertView.findViewById(R.id.tv_weekly_main_month_item_text);
            holder.img = (ImageView) convertView.findViewById(R.id.iv_weekly_main_month_item_img);
            holder.orangLine = convertView.findViewById(R.id.weekly_main_month_item_line_orange);
            holder.blackLine = convertView.findViewById(R.id.weekly_main_month_item_line_black);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.text.setText(strings[position]);
        if (type == 0) {
            holder.orangLine.setVisibility(View.GONE);
            holder.blackLine.setVisibility(View.VISIBLE);
            if (yearPostion == position) {
                holder.img.setVisibility(View.VISIBLE);
            } else {
                holder.img.setVisibility(View.GONE);
            }
        } else {
            holder.blackLine.setVisibility(View.GONE);
            holder.orangLine.setVisibility(View.VISIBLE);
            if (monthPosition == position) {
                holder.img.setVisibility(View.VISIBLE);
                holder.orangLine.setBackgroundResource(R.color.weekly_main_orange_line);
            } else {
                holder.img.setVisibility(View.GONE);
                holder.orangLine.setBackgroundResource(R.color.white);

            }

        }


        return convertView;
    }

    class ViewHolder {
        TextView text;
        ImageView img;
        View orangLine;
        View blackLine;

    }

}
